﻿//------------------------------------------------------------------------------------------------- 
// <copyright file="StructureMapExtensions.cs" company="Christopher Hines">
// Copyright (c) Christopher Hines. All rights reserved.
// </copyright>
// <summary>
//    Provides extensions to the StructureMap API
// </summary>
//-------------------------------------------------------------------------------------------------

namespace Copperfield.Sdk
{
    using StructureMap;

    /// <summary>
    /// Provides extensions to the StructureMap API
    /// </summary>
    public static class StructureMapExtensions
    {
        /// <summary>
        /// Initializes a new configuration expression
        /// </summary>
        /// <param name="iocExpression">The IoC Expression</param>
        /// <returns>A new configuration expression</returns>
        public static StructureMapConfigurationExpression EnableContextBasedResolution(this IInitializationExpression iocExpression)
        {
            // Set the standard resolution method for a single instance
            CopperfieldConfiguration.InstancesAreResolvedBy(ObjectFactory.GetInstance);

            // Set how instances are configured
            CopperfieldConfiguration.ConfigurePluginInstances((plugin, context, resolution) => iocExpression.For(plugin).Use(container => resolution(plugin, context)));

            return new StructureMapConfigurationExpression { IocExpression = iocExpression };
        }
    }
}
